﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuantitativeInvestment.Bean;
using QuantitativeInvestment.Tools;

namespace QuantitativeInvestment.Factor
{
    class AroonFactor:Factor
    {
        public AroonFactor()
        {
            this.name = "阿隆指标";
            Parameter p = new Parameter("天数",30);
            this.paraList.Add(p.name,p);
        }
        public override void addFactorValue(Stock stock)
        {
            int num = Int32.Parse(this.paraList["天数"].value.ToString());

            if (!stock.factors.ContainsKey(this.name + this.paraList["天数"].value.ToString()))
            {
                TaLib lib = new TaLib();

                double[,] aroonValues = lib.getAroon(stock.factors["最高价"], stock.factors["最底价"], num);
                int length=stock.factors["最高价"].Length;

                double[] result1 = new double[length];
                double[] result2 = new double[length];

                for (int i = 0; i < length; i++)
                {
                    result1[i] = aroonValues[0, i];
                    result2[i] = aroonValues[1, i];
                }
                stock.factors.Add(this.name + this.paraList["天数"].value.ToString() + "上升", result1);
                stock.factors.Add(this.name + this.paraList["天数"].value.ToString() + "下降", result2);
                }
        }
    }
}
